fix: pass reason= keyword arg to web.HTTPBadRequest in emu_svc#51
fix: pass reason= keyword arg to web.HTTPBadRequest in emu_svc#51
Conversation
aiohttp >= 3.x raises TypeError when web.HTTPBadRequest() is called with a positional argument. The error message must be passed as reason=<str>. Affected: handle_forwarded_beacon exception handler in emu_svc.py
There was a problem hiding this comment.
Pull request overview
Fixes an aiohttp exception-construction bug in the emu forwarded beacon HTTP handler so error paths correctly return a 400 response instead of failing with a TypeError and producing a 500.
Changes:
- Update
handle_forwarded_beaconto raiseweb.HTTPBadRequestusing thereason=keyword argument (aiohttp 3.x+ compatible).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except Exception as e: | ||
| error_msg = 'Server error when processing forwarded beacon: %s' % e | ||
| self.log.error(error_msg) | ||
| raise web.HTTPBadRequest(error_msg) | ||
| raise web.HTTPBadRequest(reason=error_msg) |
Adds a test verifying that handle_forwarded_beacon raises web.HTTPBadRequest with a non-empty reason= kwarg when the request body contains invalid JSON, covering the runtime failure path fixed in the previous commit.
|
There was a problem hiding this comment.
Pull request overview
Fixes handle_forwarded_beacon to raise aiohttp.web.HTTPBadRequest using the supported reason= keyword argument (avoiding a TypeError that previously caused 500s instead of 400s).
Changes:
- Update
emu_svc.handle_forwarded_beaconto callweb.HTTPBadRequest(reason=...). - Add a regression test covering malformed JSON causing
HTTPBadRequestto be raised.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/emu_svc.py | Fixes aiohttp exception construction to avoid TypeError and return intended 400 responses. |
| tests/test_emu_svc.py | Adds regression coverage to ensure malformed forwarded beacon bodies result in HTTPBadRequest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| error_msg = 'Server error when processing forwarded beacon: %s' % e | ||
| self.log.error(error_msg) | ||
| raise web.HTTPBadRequest(error_msg) | ||
| raise web.HTTPBadRequest(reason=error_msg) |
| assert exc_info.value.reason is not None | ||
| assert len(exc_info.value.reason) > 0 |
There was a problem hiding this comment.
Pull request overview
Fixes an aiohttp compatibility issue in the forwarded beacon handler so it reliably returns a 400 Bad Request instead of erroring while constructing the exception (500).
Changes:
- Update
handle_forwarded_beaconto pass the error message viareason=toweb.HTTPBadRequest(aiohttp 3.x compatible). - Add a regression test ensuring malformed JSON in the forwarded beacon request results in
HTTPBadRequest.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
app/emu_svc.py |
Fixes HTTPBadRequest construction to avoid TypeError and restore intended 400 behavior. |
tests/test_emu_svc.py |
Adds regression coverage for malformed JSON triggering HTTPBadRequest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| error_msg = 'Server error when processing forwarded beacon: %s' % e | ||
| self.log.error(error_msg) | ||
| raise web.HTTPBadRequest(error_msg) | ||
| raise web.HTTPBadRequest(reason=error_msg) |
| assert exc_info.value.reason is not None | ||
| assert len(exc_info.value.reason) > 0 |




Summary
handle_forwarded_beaconinemu_svc.pywas callingweb.HTTPBadRequest(error_msg)with a positional argument. In aiohttp >= 3.x the exception constructor does not accept positional message arguments — the message must be passed asreason=<str>.Before:
After:
Impact
When the forwarded beacon handler catches any exception (e.g. invalid JSON from the forwarded agent, network error, unexpected server error), the
HTTPBadRequestconstructor itself raisesTypeError: __init__() takes 1 positional argument but 2 were given. This causes an unhandled exception in the aiohttp request handler, resulting in a 500 Internal Server Error instead of the intended 400 Bad Request response.Test plan